package net.lanelife.casino.caipiao.dto.admin;

import java.util.List;

import javax.persistence.criteria.CriteriaBuilder;
import javax.persistence.criteria.CriteriaQuery;
import javax.persistence.criteria.Root;
import javax.persistence.criteria.Selection;

import net.lanelife.casino.caipiao.entity.BankTransactionDetail;
import net.lanelife.casino.caipiao.entity.BankTransactionDetail_;
import net.lanelife.casino.common.dto.support.GenericTable;
import net.lanelife.casino.common.entity.json.serialize.CurrencySerializer;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.google.common.collect.Lists;

/**
 * @author Lane
 * 
 * 银行交易明细表格
 *
 * @param <DTO>
 */
public class BankTransactionDetailTable<DTO> extends GenericTable<DTO, BankTransactionDetail> {

	private static final long serialVersionUID = 8012451421369520196L;
	
	@JsonSerialize(using = CurrencySerializer.class)
	private Double transactionAmountIn;
	
	@JsonSerialize(using = CurrencySerializer.class)
	private Double transactionAmountOut;
	
	@JsonSerialize(using = CurrencySerializer.class)
	private Double transactionFee;

	public BankTransactionDetailTable() {}

	public BankTransactionDetailTable(Double transactionAmountIn, Double transactionAmountOut, Double transactionFee) {
		super();
		this.transactionAmountIn = transactionAmountIn;
		this.transactionAmountOut = transactionAmountOut;
		this.transactionFee = transactionFee;
	}

	@Override
	public List<Selection<?>> buildExpression(Root<BankTransactionDetail> root, CriteriaQuery<?> query, CriteriaBuilder builder) {
		List<Selection<?>> columns = Lists.newArrayList();
		columns.add(builder.sum(builder.<Double>selectCase().when(builder.equal(root.get(BankTransactionDetail_.transactionDirection), BankTransactionDetail.TransactionDirection.IN), root.<Double>get(BankTransactionDetail_.transactionAmount)).otherwise(0D)));
		columns.add(builder.sum(builder.<Double>selectCase().when(builder.equal(root.get(BankTransactionDetail_.transactionDirection), BankTransactionDetail.TransactionDirection.OUT), root.<Double>get(BankTransactionDetail_.transactionAmount)).otherwise(0D)));
		columns.add(builder.sum(root.get(BankTransactionDetail_.transactionFee)));
		return columns;
	}

	public Double getTransactionAmountIn() {
		return transactionAmountIn;
	}

	public void setTransactionAmountIn(Double transactionAmountIn) {
		this.transactionAmountIn = transactionAmountIn;
	}

	public Double getTransactionAmountOut() {
		return transactionAmountOut;
	}

	public void setTransactionAmountOut(Double transactionAmountOut) {
		this.transactionAmountOut = transactionAmountOut;
	}

	public Double getTransactionFee() {
		return transactionFee;
	}

	public void setTransactionFee(Double transactionFee) {
		this.transactionFee = transactionFee;
	}

}
